﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;

using InfFront.InfoSources.Base;
using InfFront.InfoViews.Base;

namespace InfFront.InfoViews.WPF.Settings
{
    internal partial class SettingsInfoSet : DummyInfoSource
    {
        #region Private Variables
        private RootInfoViewSource source;
        #endregion Private Variables

        public SettingsInfoSet()
        {
            InitializeComponent();
        }

        public SettingsInfoSet(IContainer container)
        {
            container.Add(this);

            InitializeComponent();
        }

        [Browsable(false)]
        public RootInfoViewSource Source
        {
            get { return source; }
            set 
            { 
                source = value;
                infoRootSettings.ViewSet = value;
            }
        }

        public string[] TranslateInfoViewPathToSettingsPath(string[] path)
        {
            if (path == null || path.Length == 0)
                return new string[] { infoRootSettings.Name };
            var newpath = new string[path.Length + 1];
            newpath[0] = pagesDummyInfoSource.Name;
            for (int i = 0; i < path.Length; ++i)
                newpath[i + 1] = InfoSourceSettingsInfoSource.TranslateInfoViewNameToSettingsName(path[i]);
            return newpath;
        }

        private void pagesDummyInfoSource_BeforeGetNestedSources(object sender, EventArgs e)
        {
            if (pagesDummyInfoSource.NestedSources.Count == 0)
            {
                foreach (var vsrc in Source.NestedSources)
                {
                    var src = new InfoSourceSettingsInfoSource() { ViewSource = vsrc };
                    pagesDummyInfoSource.NestedSources.Add(src);
                }
            }
        }
    }
}
